package com.hyf.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {
   // @Before("execution(* com.hyf.annotation.*.*(..))")
    @Pointcut("execution(* com.hyf.annotation.*.*(..))")
    public void all(){}
    @Before("all()")

    public void before(){
        System.out.println("before");
    }
    @After("MyAspect.all()")
    public void after(){
        System.out.println("后置通知");
    }
    @Around("MyAspect.all()")
    public Object around(ProceedingJoinPoint joinPoint)throws Throwable{
        Object[] args=joinPoint.getArgs();
        System.out.println("环绕");
        Object proceed = joinPoint.proceed(args);
        System.out.println("环绕通知");
        return proceed;
    }
    @AfterThrowing(value = "MyAspect.all()",throwing = "e")
    public void afterThrowing(Exception e){
        System.out.println("异常");
    }
    @AfterReturning(value = "MyAspect.all()",returning = "result")
    public void afterReturning(Object result){
        System.out.println("返回");
    }
}
